clear all
set more off
set scheme s2color

grstyle init
grstyle color ci_area gs12%50
grstyle color ci_arealine gs12%0
grstyle linewidth plineplot medthick

// Des stat commute

global input "...\replication\data"
global output "...\replication\outputs"

use "$input\com_data.dta", clear

** Make graphs
ren com_res com
drop if substr(com,2,1) == "A"
drop if substr(com,2,1) == "B"
destring com, replace
merge m:1 com using "$input\com_arcgis.dta"
drop if _merge != 3
drop _merge
keep if dist_nat_border < 0

gen log_ind = log(ind)
egen sum_ind = sum(ind), by(com)
gen p_ind = ind/sum_ind

gen r_dist_border = round(dist_border,1)

collapse (mean) p_ind ind, by(r_dist_border same)

keep if abs(r_dist_border) <= 20

twoway (scatter p_ind r_dist_border if same == -1) (qfitci p_ind r_dist_border if same == -1, clstyle(p1line)) ///
(scatter p_ind r_dist_border if same == 0) (qfitci p_ind r_dist_border if same == 0, clstyle(p2line)), ///
graphregion(color(white)) bgcolor(white) legend(off) ///
xtitle("Distance to the border (km)",size(medium)) ///
title("Dept. A _______________________________ Dept. B") ///
ytitle("Share of local residents working in region B",size(medium)) xline(0) ///
xlabel(-20(5)20, format(%9.0g))
graph export "$output\com_data_p_ind.pdf", replace


